<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="tag" uri="http://www.springframework.org/tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/views/includes/css/style.css" />
<title>Manage - Post feed</title>
</head>
<body>
    <div id="wrapper">
    <jsp:include page="../includes/loginFB.jsp">
        <jsp:param name="perms" value="read_stream,publish_stream,offline_access,email,manage_pages"/>
    </jsp:include>
        
    <div id="app-title"><h1>Ad-campaign-facebook application</h1></div>
    <%@ include file="../includes/navigation.jsp" %>
    
    <div id='fb-root'></div>
    <script src='http://connect.facebook.net/en_US/all.js'></script>
    <form:form commandName="feed">
    <div id="feed-wrapper">
        Treść: <br /><form:textarea path="feedPost" id="feedPost"/><br />
        Link: <br /><form:textarea path="feedLink" id="feedLink"/><br />
        Obraz: <br /> <form:textarea path="feedPicture" id="feedPicture"/><br />         
        <!-- <button id="feed-submit" name="submit" onclick="postToFeed(); return false;">Post</button> -->
	    <br/><form:checkbox path="sendToOtherServices"/>Umieść na pozostałych serwisach <br />
        <p id='msg'></p>
    </div>
    <input type="submit" onclick="postToFeed();return true;"/>
	<!-- <input id="feed-submit" type="submit" onclick="postToFeed(); return false;"/> -->
    </form:form>
    <script>     

        function postToFeed() {
            if(document.getElementById("feedPost").value == '')
            {
                alert('Napisz coś');
            }
            else
            {
                var txt = document.getElementById('feedPost').value;
                var hyperlink = document.getElementById('feedLink').value;
                var image = document.getElementById('feedPicture').value;
                
                var dataObject = new Object();
                if(typeof txt != 'undefined'){
	                dataObject.message = txt;
                }
                if(typeof hyperlink != 'undefined'){
	                dataObject.link = hyperlink;
                }
                if(typeof image != 'undefined'){
	                dataObject.picture = image;
                }
                
                FB.api('/me/feed', 'post', dataObject, function(response) {
                  if (!response || response.error) {
                    alert('Wystąpił błąd');
                  } else {
                    alert('Dodano treść o ID: ' + response.id);
                  }
                });
            }
      }
     
    
    </script>
 </div>
</body>
</html>